package servlet;

import bean.Class;
import service.ClassService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 10:42 下午 2021/6/6
 */
@WebServlet(name = "UpdateClassServlet",urlPatterns = "/updateClass")
public class UpdateClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Class classes=new Class();
        int classNo = Integer.parseInt(request.getParameter("classNo").trim());
        classes.setClassNo(classNo);
        String className = request.getParameter("className");
        classes.setClassName(className);
        int gradeNo = Integer.parseInt(request.getParameter("gradeNo").trim());
        classes.setGradeNo(gradeNo);
        String teacherName = request.getParameter("teacherName");
        classes.setTeacherName(teacherName);
        String classSlogan = request.getParameter("classSlogan");
        classes.setClassSlogan(classSlogan);
        int classNum = Integer.parseInt(request.getParameter("classNum"));
        classes.setClassNum(classNum);
        System.out.println(classes.toString());
        ClassService classService=new ClassService();
        boolean isSuccess=classService.updateClass(classes);
        if(isSuccess==true){
            response.sendRedirect("updateClassAlert.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
